#ifndef			TCPCONNECTION_H
#define			TCPCONNECTION_H

#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include "ftrigger.hpp"

class TcpConnection : public boost::enable_shared_from_this<TcpConnection>
{
public:
  typedef boost::shared_ptr<TcpConnection> pointer;

  static pointer		create(boost::asio::io_service &ios);
  boost::asio::ip::tcp::socket&	socket();
  void				start(const std::string &storage);

private:
  boost::asio::ip::tcp::socket	sock;
  std::string			st_path;
  union u_ft_request		header;
  struct s_ft_request		currentCmd;
  int				action;
  char				buf[BUFSZ];

  TcpConnection(boost::asio::io_service &ios) : sock(ios)
  {
    currentCmd.type = -1;
    currentCmd.data_sz = 0;
    action = -1;
  }
  void handleRead(const boost::system::error_code &error);
  void handleWrite(const boost::system::error_code &error);
};

#endif
